package cn.gcyl.module.biz.service.projectprocurementinformation;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.gcyl.module.biz.controller.admin.projectprocurementinformation.vo.*;
import cn.gcyl.module.biz.dal.dataobject.projectprocurementinformation.ProjectProcurementInformationDO;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.util.object.BeanUtils;

import cn.gcyl.module.biz.dal.mysql.projectprocurementinformation.ProjectProcurementInformationMapper;

import static cn.gcyl.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.gcyl.framework.common.util.collection.CollectionUtils.convertList;
import static cn.gcyl.framework.common.util.collection.CollectionUtils.diffList;
import static cn.gcyl.module.system.enums.ErrorCodeConstants.PROJECT_PROCUREMENT_INFORMATION_NOT_EXISTS;

/**
 * 项目采购信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ProjectProcurementInformationServiceImpl implements ProjectProcurementInformationService {

    @Resource
    private ProjectProcurementInformationMapper projectProcurementInformationMapper;

    @Override
    public Long createProjectProcurementInformation(ProjectProcurementInformationSaveReqVO createReqVO) {
        // 插入
        ProjectProcurementInformationDO projectProcurementInformation = BeanUtils.toBean(createReqVO, ProjectProcurementInformationDO.class);
        projectProcurementInformationMapper.insert(projectProcurementInformation);

        // 返回
        return projectProcurementInformation.getId();
    }

    @Override
    public void updateProjectProcurementInformation(ProjectProcurementInformationSaveReqVO updateReqVO) {
        // 校验存在
        validateProjectProcurementInformationExists(updateReqVO.getId());
        // 更新
        ProjectProcurementInformationDO updateObj = BeanUtils.toBean(updateReqVO, ProjectProcurementInformationDO.class);
        projectProcurementInformationMapper.updateById(updateObj);
    }

    @Override
    public void deleteProjectProcurementInformation(Long id) {
        // 校验存在
        validateProjectProcurementInformationExists(id);
        // 删除
        projectProcurementInformationMapper.deleteById(id);
    }

    @Override
        public void deleteProjectProcurementInformationListByIds(List<Long> ids) {
        // 删除
        projectProcurementInformationMapper.deleteByIds(ids);
        }


    private void validateProjectProcurementInformationExists(Long id) {
        if (projectProcurementInformationMapper.selectById(id) == null) {
            throw exception(PROJECT_PROCUREMENT_INFORMATION_NOT_EXISTS);
        }
    }

    @Override
    public ProjectProcurementInformationDO getProjectProcurementInformation(Long id) {
        return projectProcurementInformationMapper.selectById(id);
    }

    @Override
    public PageResult<ProjectProcurementInformationDO> getProjectProcurementInformationPage(ProjectProcurementInformationPageReqVO pageReqVO) {
        return projectProcurementInformationMapper.selectPage(pageReqVO);
    }

}